

<!DOCTYPE html>
<html>
    <head>
        <title>文章分享测试</title>
        <link rel="stylesheet" href="/stylesheets/weui.css">
        <meta name="viewport" content="initial-scale=1,maximum-scale=1,minimum-scale=1">
    </head>
    <body>
			<h1 style="color:red" id="shareId"></h1>
       	<%- include('./articleTemp.ejs'); %>
        <script src="https://res2.wx.qq.com/open/js/jweixin-1.6.0.js"></script>

    </body>
    <script>
        wx.config({
            debug   	:false,
            appId		:'wx8adf122f1d98838b',
            timestamp 	:'<%= timestamp %>',
            nonceStr 	:'<%= noncestr %>',
            signature 	:'<%= signature %>',
            jsApiList 	:[
                'startRecord',
                'stopRecord',
                'onVoiceRecord',
                'translateVoice',
                'updateTimelineShareData',
                'updateAppMessageShareData',
                'onMenuShareQQ',
                'onMenuShareWeibo',
                'onMenuShareQZone',
            ]
        })

        wx.ready(function(){
            wx.checkJsApi({
                jsApiList:['updateTimelineShareData',
                'updateAppMessageShareData'],
                success:function(res){
                    console.log(res);
                }
            })
            var shareContent = {
                title : '文章分享测试',
                desc  : '微信公众号后台开发之分享功能 ',
                link  : `${location.href}?userId=<%= user.nickname %>`,
                imgUrl : 'https://inews.gtimg.com/newsapp_ls/0/12626694159_294195/0',
                type : 'link' ,
                dataUrl : '',
                success : function(){
                    console.log("分享初始化成功")
                },cancel : function(){
                    console.log("分享初始化失败")
                }
            };
            wx.updateAppMessageShareData(shareContent);

        })

				wx.error(function(res){
  // config信息验证失败会执行error函数，如签名过期导致验证失败，具体错误信息可以打开config的debug模式查看，也可以在返回的res参数中查看，对于SPA可以在这里更新签名。
	console.error("wx配置失败，",res)
});

function getQueryVariable(variable)
{
       var query = window.location.search.substring(1);
       var vars = query.split("&");
       for (var i=0;i<vars.length;i++) {
               var pair = vars[i].split("=");
               if(pair[0] == variable){return pair[1];}
       }
       return(false);
}
let userId = getQueryVariable('userId')
// 确定分享人
if(userId){
	document.querySelector('#shareId').innerHTML = `这是来自${decodeURIComponent(userId) }分享给你的网页`
}
        

    </script>
</html>


